home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / KBANDATA / LINEELEM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-23  |  2.8 KB  |  119 lines

  1. /*
  2.  * the class LINE_ELEMENT
  3.  * Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  4.  */
  5.  
  6. #include "../common/bool.h"
  7.  
  8. #include "../kbandef.h"
  9.  
  10. #include "lineelem.h"
  11.  
  12. #define outside(x, y, z) (((y) <= (x)) || ((z) <= (y)))
  13.  
  14. void LINE_ELEMENT::save_200a8(FILE_NEW& fp) const
  15. {
  16.   fp.printf("%d %d %d %d %d\n",
  17.     ac_s().x(),
  18.     ac_s().y(),
  19.     ac_e().x(),
  20.     ac_e().y(),
  21.     width()
  22.   );
  23. }
  24.  
  25. int LINE_ELEMENT::load_170_core(const char *str)
  26. {
  27.   XYT x1, y1, x2, y2;
  28.   uint width;
  29.   sscanf(str, "%d %d %d %d %d", &x1, &y1, &x2, &y2, &width);
  30.   x1 = x1 * 25400 / 300;
  31.   y1 = y1 * 25400 / 300;
  32.   x2 = x2 * 25400 / 300;
  33.   y2 = y2 * 25400 / 300;
  34.   width = width * 25400 / 1000;
  35.   set_ac_s(XY(x1, y1));
  36.   set_ac_e(XY(x2, y2));
  37.   set_width(width);
  38.   return true;
  39. }
  40.  
  41. int LINE_ELEMENT::load_primitive_170(const char *str)
  42. {
  43.   load_170_core(str);
  44.   set_ac_s(XY(ac_s().x(), Y_V1TOV2 - ac_s().y()));
  45.   set_ac_e(XY(ac_e().x(), Y_V1TOV2 - ac_e().y()));
  46.   return true;
  47. }
  48.  
  49. int LINE_ELEMENT::load_component_170(const char *str)
  50. {
  51.   load_170_core(str);
  52.   set_ac_s(XY(ac_s().x(), - ac_s().y()));
  53.   set_ac_e(XY(ac_e().x(), - ac_e().y()));
  54.   return true;
  55. }
  56.  
  57. int LINE_ELEMENT::unit_change_micron2kban(int micron)
  58. {
  59.   return micron * DIS_MICRON;
  60. }
  61.  
  62. void LINE_ELEMENT::load_200a8(const char* str)
  63. {
  64.   XYT x1, y1, x2, y2;
  65.   uint width;
  66.   sscanf(str, "%d %d %d %d %d", &x1, &y1, &x2, &y2, &width);
  67.   x1     = unit_change_micron2kban(x1);
  68.   y1     = unit_change_micron2kban(y1);
  69.   x2     = unit_change_micron2kban(x2);
  70.   y2     = unit_change_micron2kban(y2);
  71.   width  = unit_change_micron2kban(width);
  72.   XY ac1(x1, y1);
  73.   XY ac2(x2, y2);
  74.   set_ac_s(ac1);
  75.   set_ac_e(ac2);
  76.   set_width(width);
  77. }
  78.  
  79. int LINE_ELEMENT::is_on_line(XYT eps, const XY& ac)
  80. {
  81.   int result;
  82.  
  83.   uint w = maximum(width(), uint(eps));
  84.   if(is_holizontal()) {
  85.     XY p(ac_s().x(), ac_s().y() - w / 2);
  86.     XY q(ac_e().x(), ac_s().y() + w / 2);
  87.     result = ac.is_in_box(p, q);
  88.   } else if(is_vertical()) {
  89.     XY p(ac_s().x() - w / 2, ac_s().y());
  90.     XY q(ac_s().x() + w / 2, ac_e().y());
  91.     result = ac.is_in_box(p, q);
  92.   } else {
  93.     XY ac_o, ac_p;
  94.     if(ac_s().y() < ac_e().y()) {
  95.       ac_o = ac_s();
  96.       ac_p = ac_e();
  97.     } else {
  98.       ac_o = ac_e();
  99.       ac_p = ac_s();
  100.     }
  101.     double rad = - ac_o.get_radian(ac_p);
  102.     XY ac_s_moved = ac_s() - ac;
  103.     XY ac_e_moved = ac_e() - ac;
  104.     ac_s_moved.rotate(ac_s_moved, rad);
  105.     ac_e_moved.rotate(ac_e_moved, rad);
  106.     XY ac_origin(0, 0);
  107.     XY p(ac_s_moved.x(), ac_s_moved.y() - w / 2);
  108.     XY q(ac_e_moved.x(), ac_s_moved.y() + w / 2);
  109.     result = ac_origin.is_in_box(p, q);
  110.   }
  111.   return result;
  112. }
  113.  
  114. void LINE_ELEMENT::rotate_90()
  115. {
  116.   m_ac_s.rotate_90();
  117.   m_ac_e.rotate_90();
  118. }
  119.